<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function addCartItem($id,$name,$cost) {
	$value = get_cookie('mywow_cart').$id.'&'.$name.'&'.$cost.'&&';
	saveToCookie($value);
}

function getCartItems() {
	$value = get_cookie('mywow_cart');
	$cookies = explode('&&', $value);
	$result = array();
	for ($i=0;$i<count($cookies);$i++) {
		$cookie = explode('&', $cookies[$i]);
		$result[$i-1] = $cookie;
	}

	return $result;
}

function changeCount($id,$count) {

}

function newValue($cart) {
	$value = '';
	foreach ($cart as $item) 
		{
    		$value = $value.'&&'.$item[0].'&'.$item[1].'&'.$item[2];
    	}
    return $value;
}

function saveToCookie($value) {
	$cookie = array(
    'name'   => 'mywow_cart',
    'value'  => $value,
    'expire' => '0',
    'domain' => '',
    'path'   => '/',
    'prefix' => '',
    'secure' => FALSE
	);
	set_cookie($cookie);
}

function deleteCartItem($id) {
	$cart = getCartItems();
	$value = '';
	foreach ($cart as $item) 
		if ($item[0]!=$id)
		{
    		$value = $value.'&&'.$item[0].'&'.$item[1].'&'.$item[2];
    	}
    saveToCookie($value);
}

